﻿using System;
using System.IO;

namespace KingdeeWebServiceProject.Utils
{
    class LogHelper
    {
        //System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName //获取类名
        // Exception ex //ex.StackTrace //行号


        private static readonly string DirectoryPath = "D://WebServiceLog"; //Environment.CurrentDirectory + "\\Log";

        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="className"></param>
        /// <param name="logText"></param>
        public static void WirteLog(string fileName, string className, string logText)
        {
            try
            {
                if (!Directory.Exists(DirectoryPath))
                {
                    Directory.CreateDirectory(DirectoryPath);
                }
                string strLogFileName = DirectoryPath + "\\" + fileName + DateTime.Today.ToString("yyyyMMdd") + ".log";
                using (StreamWriter sw = new StreamWriter(strLogFileName, true))
                {
                    if (logText.Trim().Equals(""))
                    {
                        sw.WriteLine("");
                    }
                    else
                    {
                        string str2 = DateTime.Now.ToString("HH:mm:ss,fff ") + " -【" + className + "】  ";
                        sw.WriteLine(str2);
                        sw.WriteLine(logText);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
